<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="编号" prop="changeNumber">
        <el-input
          v-model="queryParams.changeNumber"
          placeholder="请输入编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学生姓名" prop="studentName">
        <el-input
          v-model="queryParams.studentName"
          placeholder="请输入学生姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="异动类型" prop="changeType">
        <el-select
          v-model="queryParams.changeType"
          placeholder="请选择异动类型"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in this.getDictDatas(DICT_TYPE.STUDENT_CHANGE_TYPE)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态" prop="checkStatus">
        <el-select
          v-model="queryParams.checkStatus"
          placeholder="请选择审核状态"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in this.getDictDatas(DICT_TYPE.CHANGE_CHECK_STATUS)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="异动时间" prop="changeTime">
        <!-- <el-date-picker
          v-model="queryParams.changeTime"
          style="width: 240px"
          value-format="yyyy-MM-dd HH:mm:ss"
          :default-time="['00:00:00', '23:59:59']"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        /> -->
        <el-date-picker
          type="date"
          value-format="yyyy-MM-dd"
          v-model="queryParams.changeStartTime"
          placeholder="开始日期"
        ></el-date-picker
        ><span>-</span
        ><el-date-picker
          type="date"
          v-model="queryParams.changeEndTime"
          value-format="yyyy-MM-dd"
          placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery"
          >搜索
        </el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          @click="handleAdd"
          v-hasPermi="['collegebase:student-change:create']"
          >新增
        </el-button>
      </el-col>
      <!--  <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            @click="handleExport"
            :loading="exportLoading"
            v-hasPermi="['collegebase:student-change:export']"
            >导出</el-button
          >
        </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          @click="handleExamine"
          :disabled="sourceId == '' ? true : false"
          >审核
        </el-button>
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
        :columns="columns"
      ></right-toolbar>
    </el-row>

    <!-- 列表 -->
    <el-table
      v-loading="loading"
      :data="list"
      @selection-change="handleSelectionChange"
    >
      <!--      <el-table-column type="checkbox" width="50"> </el-table-column>-->
      <el-table-column label width="35">
        <template slot-scope="scope">
          <el-radio
            :label="scope.row.id"
            v-model="sourceId"
            :disabled="scope.row.checkStatus == 3"
          ></el-radio>
        </template>
      </el-table-column>
      <el-table-column
        label="编号"
        align="center"
        prop="changeNumber"
        v-if="columns[0].visible"
        min-width="110px"
      />
      <el-table-column
        label="机构编号"
        align="center"
        prop="orgId"
        v-if="columns[1].visible"
        show-overflow-tooltip
      />
      <el-table-column
        label="学号"
        align="center"
        prop="studentNumber"
        v-if="columns[2].visible"
        show-overflow-tooltip
      />
      <el-table-column
        label="法号"
        align="center"
        prop="legalName"
        v-if="columns[3].visible"
        show-overflow-tooltip
      />
      <el-table-column
        label="学生姓名"
        align="center"
        prop="studentName"
        v-if="columns[4].visible"
        show-overflow-tooltip
      />
      <el-table-column
        label="异动时间"
        align="center"
        prop="changeTime"
        width="105px"
        v-if="columns[5].visible"
        key="5"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.changeTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="异动类型"
        align="center"
        prop="changeType"
        v-if="columns[6].visible"
        key="6"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <dict-tag
            :type="DICT_TYPE.STUDENT_CHANGE_TYPE"
            :value="scope.row.changeType"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="原系部"
        align="center"
        prop="oldDepartment"
        v-if="columns[7].visible"
        show-overflow-tooltip
      />
      <el-table-column
        label="原专业"
        align="center"
        prop="oldMajor"
        v-if="columns[8].visible"
        show-overflow-tooltip
      />
      <el-table-column
        label="原班级"
        align="center"
        prop="oldClassGrade"
        v-if="columns[9].visible"
        show-overflow-tooltip
      />
      <el-table-column
        label="原年级"
        align="center"
        prop="oldYearGrade"
        v-if="columns[10].visible"
        show-overflow-tooltip
      />
      <el-table-column
        label="现系部"
        align="center"
        prop="departmentName"
        v-if="columns[11].visible"
        show-overflow-tooltip
      />
      <el-table-column
        label="现专业"
        align="center"
        prop="professionName"
        v-if="columns[12].visible"
        show-overflow-tooltip
      />
      <el-table-column
        label="现班级"
        align="center"
        prop="classesName"
        v-if="columns[13].visible"
        show-overflow-tooltip
      />
      <el-table-column
        label="现年级"
        align="center"
        prop="newYearGrade"
        v-if="columns[14].visible"
        show-overflow-tooltip
      />
      <el-table-column
        label="审核状态"
        align="center"
        prop="checkStatus"
        v-if="columns[15].visible"
        show-overflow-tooltip
        key="15"
      >
        <template slot-scope="scope">
          <dict-tag
            :type="DICT_TYPE.CHANGE_CHECK_STATUS"
            :value="scope.row.checkStatus"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="审核人"
        align="center"
        prop="checkUser"
        v-if="columns[16].visible"
        show-overflow-tooltip
      />
      <el-table-column
        label="审核时间"
        align="center"
        prop="checkTime"
        width="180px"
        v-if="columns[17].visible"
        key="17"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="审核备注"
        align="center"
        prop="checkRemark"
        v-if="columns[18].visible"
        show-overflow-tooltip
      />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="165px"
        v-if="columns[19].visible"
        key="19"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        min-width="100px"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['collegebase:student-change:update']"
            >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['collegebase:student-change:delete']"
            >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加修改组件 -->
    <form-edit
      :show.sync="open"
      :title="title"
      @success="getList"
      ref="editDialog"
    ></form-edit>
    <!-- 添加审核组件 -->
    <examine
      ref="examineDialog"
      :show.sync="examineopen"
      :handleSelectArr.sync="sourceId"
      @success="getList"
    ></examine>
  </div>
</template>

<script>
import {
  createStudentChange,
  updateStudentChange,
  deleteStudentChange,
  getStudentChange,
  getStudentChangePage,
  exportStudentChangeExcel,
} from "@/api/collegebase/studentChange";
import formEdit from "./formEdit";
import examine from "./examine.vue";

export default {
  name: "StudentChange",
  components: {
    formEdit,
    examine,
  },
  data() {
    return {
      sourceId: "",
      columns: [
        { key: 0, label: `编号`, visible: true },
        { key: 1, label: `机构编号`, visible: false },
        { key: 2, label: `学号`, visible: true },
        { key: 3, label: `法号`, visible: true },
        { key: 4, label: `学生姓名`, visible: true },
        { key: 5, label: `异动时间`, visible: true },
        { key: 6, label: `异动类型`, visible: true },
        { key: 7, label: `原系部`, visible: true },
        { key: 8, label: `原专业`, visible: true },
        { key: 9, label: `原班级`, visible: true },
        { key: 10, label: `原年级`, visible: false },
        { key: 11, label: `现系部`, visible: true },
        { key: 12, label: `现专业`, visible: true },
        { key: 13, label: `现班级`, visible: true },
        { key: 14, label: `现年级`, visible: false },
        { key: 15, label: `审核状态`, visible: true },
        { key: 16, label: `审核人`, visible: false },
        { key: 17, label: `审核时间`, visible: false },
        { key: 18, label: `审核备注`, visible: false },
        { key: 19, label: `创建时间`, visible: false },
      ],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学籍信息异动列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        changeNumber: null,
        studentName: null,
        studentId: null,
        changeType: null,
        checkStatus: null,
        changeTime: [],
        changeStartTime: null,
        changeEndTime: null
      },
      //审核显示弹出层
      examineopen: false,
      handleSelectValArr: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      getStudentChangePage(this.queryParams).then((response) => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.changeStartTime = null;
      this.queryParams.changeEndTime = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.open = true;
      this.title = "添加学籍信息异动";
      this.$refs.editDialog.initData({});
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id;
      getStudentChange(id).then((response) => {
        let form = response.data;
        this.open = true;
        this.title = "修改学籍信息异动";
        this.$refs.editDialog.initData(form);
      });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal
        .confirm('是否确认删除学籍信息异动编号为"' + row.changeNumber + '"的数据项?')
        .then(function () {
          return deleteStudentChange(id);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = { ...this.queryParams };
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.$modal
        .confirm("是否确认导出所有学籍信息异动数据项?")
        .then(() => {
          this.exportLoading = true;
          return exportStudentChangeExcel(params);
        })
        .then((response) => {
          this.$download.excel(response, "学籍信息异动.xls");
          this.exportLoading = false;
        })
        .catch(() => {
        });
    },
    /**选中事件 */
    handleSelectionChange(val) {
      this.handleSelectValArr = val;
    },
    /**审核操作 */
    handleExamine() {
      this.examineopen = true;
    },
  },
};
</script>
